<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="sb" uri="/struts-bootstrap-tags"%>
<%@ include file="/page/common/admHeader.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>企业分析列表</title>
<script type="text/javascript" src="<%=basePath%>js/tablecreate/jlinq.js"></script>
<script type="text/javascript" src="<%=basePath%>js/tablecreate/jquery-dynamicTable.js"></script>
<script type="text/javascript" src="<%=basePath%>js/tablecreate/pager.js"></script> 
<script type="text/javascript" src="<%=basePath%>js/tablecreate/modal.js"></script>
<script type="text/javascript" src="<%=basePath %>js/exporting.js"></script>
<script type="text/javascript" src="<%=basePath %>js/highcharts.4.1.4.js"></script>

<style type="text/css">
a:LINK{text-decoration: none;color:black;}
a:visited {text-decoration:none ; color:black;}
a:hover {text-decoration:underline ; color:black;}
a:active {text-decoration:none ; color:black;} 
</style>
<sb:head/>
</head>
<body  onload="adminCPSList()">

<h3>企业分析列表</h3>
<div style="width: 100%;height:36px;background:url(<%=basePath%>/image/gridbar.gif) repeat-x;">
<div style="background:url(<%=basePath%>/image/gridbar.gif) repeat-x;width: 500px;height:36px;float:left;">
<input placeholder="请输入企业名称" id="comName" class="input-medium search-query" name="comName" value=""/>
<input type="button" class="btn btn-success" id="" onclick="searchList();report();" value="查询"/>
&nbsp;&nbsp;
<img alt="" src="<%=basePath%>/image/download.png" onclick="cpsexcel()"/>
</div>
<div style="background:url(<%=basePath%>/image/gridbar.gif) repeat-x;width: 360px;height:36px;float:right;">
<select id="selDate" onchange="searchListByselDate();report();" style="width: 80px;height: 80%" >
<option value="">时间</option>
<option value='<s:property value="dateMap.currDate"/>-<s:property value="dateMap.currDate"/>'>今天</option>
<option value='<s:property value="dateMap.yesterday"/>-<s:property value="dateMap.currDate"/>'>昨天</option>
<option value='<s:property value="dateMap.day7"/>-<s:property value="dateMap.currDate"/>'>最近7天</option>
<option value="<s:property value="dateMap.day15"/>-<s:property value="dateMap.currDate"/>">最近15天</option>
<option value="<s:property value="dateMap.currMonth"/>-<s:property value="dateMap.currDate"/>">本月</option>
<option value="<s:property value="dateMap.upstartmonth"/>-<s:property value="dateMap.upendmonth"/>">上月</option>
</select>
<input placeholder="起始时间" id="sDate" type="text"  value='<s:property value='s_date'/>' style="width: 120px;height: 80%" onClick="WdatePicker()"/><input placeholder="结束时间" value='<s:property value='e_date'/>' onchange="searchListByDate();report();" id="eDate" style="width: 120px;height: 80%" type="text" onClick="WdatePicker()"/>
<img style="margin-top: -10px;" width="30px;" height="35px;" alt="" src="<%=basePath%>js/datepicker/skin/datePicker.gif">
</div>
</div>
<div id="container" style="min-width:700px;height:200px"></div>
<script type="text/javascript">
report();
function report(){
	var date=$("#selDate").val();
	if(date==null){
		 var sDate=date.substring(0,(date.length-1)/2);
		 var eDate=date.substring((date.length+1)/2,date.length);
		}else{
			var sDate=$("#sDate").val();
			var eDate=$("#eDate").val();
			}
	var postData1={comName:$("#comName").val(),s_date:sDate,e_date:eDate}
	$(function () {
		 var url = 'cps_CPSReport';
			$.post(url,postData,function(response) {
				totalProfit = response.totalProfit;
				comTotalProfit = response.comTotalProfit;
				totalNum = response.totalNum;
				profitRate = response.profitRate;
				date=response.date;
	       $('#container').highcharts({
	        title: {
	            text: '企业收益分析',
	            x: -20 //center
	        },
	        subtitle: {
	            text: 'Source:e9ding.com',
	            x: -20
	        },
	        xAxis: {
	            categories: date
	        },
	        yAxis: {
	            title: {
	                text: '收益 (￥) ，数量（份）'
	            },
	            plotLines: [{
	                value: 0,
	                width: 1,
	                color: '#808080'
	            }]
	        },
	        tooltip: {
	            valueSuffix: '￥'
	        },
	        legend: {
	            layout: 'vertical',
	            align: 'right',
	            verticalAlign: 'middle',
	            borderWidth: 0
	        },
	        series: [{
	            name: '饿9定收益',
	            data: totalProfit
	        }, {
	            name: '企业收益',
	            data: comTotalProfit
	        }, {
	            name: '卖出数量',
	            data: totalNum
	        }, {
	            name: '收益率',
	            data: profitRate
	        }]
	    });
	}, "json");  
		});
};
 
</script>
<div id="lists">
<div id="list" ></div>
<div id="page"></div>
</div>
<script type="text/javascript">
var url=[{loadUrl:"cps_getCPSs",editUrl:"",stopUrl:""}];//请求地址
var postData={comName:$("#comName").val()};
var pageId="page";
var objClassName="list_light";
var objColumn = [//这里应该还有加上企业收益
					{ ColumnName: "企业名称", DataId: "comName", Width: 200, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "企业收益", DataId: "comTotalProfit", Width: 100, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "美乐滋收益", DataId: "totalProfit", Width: 100, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "菜单卖出数量", DataId: "totalNum", Width: 100, DataAlign: "left", Format: null, OnClick: null },
					{ ColumnName: "收益率%", DataId: "profitRate", Width: 100, DataAlign: "left", Format: null, OnClick: null },
                 ];
function adminCPSList(){
	   $.ajax({
			type: "post",
	        url: url[0].loadUrl,
	        data: postData,
	        dataType: "json",
	        success: function(data){
          var objData = new Array(data.list.length);
          for(var i=0;i<data.list.length;i++){
        	  objData[i]={comName:data.list[i].comName,comTotalProfit:data.list[i].comTotalProfit,
        			  totalProfit:data.list[i].totalProfit,totalNum:data.list[i].totalNum,
        			  profitRate:data.list[i].profitRate}; 
              }
               $("#list").MakeTable(objColumn, objData, objClassName);
        	  $("#page").MakePage(data.page[0]);
		        }
			});
	   }
function searchList(){
	var page=$("#selPage").val();
	var pageRow=$("#selRow").val();
	postData={comName:$("#comName").val(),initPage:page,pageRow:pageRow};
	adminCPSList();
}
var j=0;
function OrderSort(order){
	var order=order;
	j++;
	if(j%2==0){
          var sort="desc";
		}else if (j%3==0) {
			var sort="asc";
		}else{
      order="created";
      var sort="desc";
			}
	var page=$("#selPage").val();
	var pageRow=$("#selRow").val();
	postData={comName:$("#comName").val(),order:order,sort:sort,initPage:page,pageRow:pageRow};
	adminCPSList();
}
function goPage(){
	var page=$("#selPage").val();
	var pageRow=$("#selRow").val();
	postData={comName:$("#comName").val(),initPage:page,pageRow:pageRow};
	adminCPSList();
}
function changePage(page){
	var pageRow=$("#selRow").val();
	postData={comName:$("#comName").val(),initPage:page,pageRow:pageRow};
	adminCPSList();
}
function goRow(){
	var pageRow=$("#selRow").val();
	var page=$("#selPage").val();
	adminCPSList();
}
function searchListByselDate(){
    var date=$("#selDate").val();
  //  alert(date);
    var sDate=date.substring(0,(date.length-1)/2);
    var eDate=date.substring((date.length+1)/2,date.length);
    ///alert(sDate);alert(eDate);
    var page=$("#selPage").val();
	var pageRow=$("#selRow").val();
	postData={comName:$("#comName").val(),s_date:sDate,e_date:eDate,initPage:page,pageRow:pageRow};
	adminCPSList();
}
function searchListByDate(){
	var sDate=$("#sDate").val();
	var eDate=$("#eDate").val();
	//alert(sDate);alert(eDate);
	var page=$("#selPage").val();
	var pageRow=$("#selRow").val();
	postData={comName:$("#comName").val(),s_date:sDate,e_date:eDate,initPage:page,pageRow:pageRow};
	adminCPSList();
}
function cpsexcel(){
	var comName=$("#comName").val();
	 var date=$("#selDate").val();
	 if(date!=null){
		    var sDate=date.substring(0,(date.length-1)/2);
		    var eDate=date.substring((date.length+1)/2,date.length);
		 }else{
			   var sDate=$("#sDate").val();
				var eDate=$("#eDate").val();
			 }
	  //  alert(date);
	    
	window.location.href="cps_CPSExcel?comName="+comName+"&s_date="+sDate+"&e_date="+eDate;
}
</script>
<%@ include file="/page/common/modal.jsp"%>
<%@ include file="/page/common/admFooter.jsp"%>
</body>
</html>